package com.rmi;
/**
 * RegUtil.java
 * 	A simple RMI registry manament program
 * @author Yoon Kyung Koo (yoonforh@moon.daewoo.co.kr)
 * @version 1.0 1999/05/13
 */

import java.rmi.*;
import java.rmi.registry.*;

public class RegUtil {
	public static void main(String args[]) {
		String server = null;
		boolean listing = true;
		if (args.length < 1) {
			System.out.println ("Usage: java RegUtil <remote host> [list|unbind <name>]");
			System.exit(1);
		} else {
			server = args[0];
			if (args.length >= 3 &&  args[1].equals("unbind"))
				listing = false;
		}

		try {
			if (listing) {
				String[] list = LocateRegistry.getRegistry(server).list();
				if (list.length == 0)
					System.out.println("Nothing bound");
				else {
					for  (int i=0; i<list.length; i++) 
						System.out.println("name["+i+"]:"+list[i]);
				}
			}
			else { // unbind mode
				try {
					LocateRegistry.getRegistry(server).unbind(args[2]);
					System.out.println(args[2]+" unbound successfully.");
				} catch (NotBoundException nbe) {
					System.err.println("Error:"+args[2]+" is not bound.");
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}